package cn.aitrox.ry.app.web.controller.anno;

import cn.aitrox.ry.app.web.vo.anno.lesion.result.group.out.AlrgCreateOutVo;
import cn.aitrox.ry.bean.RespResult;
import cn.aitrox.ry.common.controller.BaseController;
import cn.aitrox.ry.enumtype.RespCodeEnum;
import cn.aitrox.ry.service.anno.dto.anno.lesion.result.group.in.AlrgCreateInDto;
import cn.aitrox.ry.service.anno.dto.anno.lesion.result.group.in.AlrgUpdateInDto;
import cn.aitrox.ry.service.anno.enumtype.anno.LesionResultGroupTypeEnum;
import cn.aitrox.ry.service.anno.feign.LesionResultGroupFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LesionResultGroupController extends BaseController {

    @Autowired
    @Lazy
    private LesionResultGroupFeign lesionResultGroupFeign;

    @PostMapping(value = "/anno/lesion/result/group")
    public RespResult<AlrgCreateOutVo> create(@Validated @RequestBody AlrgCreateInDto input) {
        // 校验类型
        if (!LesionResultGroupTypeEnum.VIDEO_FRAME_SEGMENT.getType().equals(input.getType())) {
            return RespResult.secByError(RespCodeEnum.PARAM_ERROR.getCode(), "类型错误");
        }
        RespResult<Integer> respResult = lesionResultGroupFeign.create(input);
        if (!respResult._isOk()) {
            return RespResult.secByError(respResult.getCode(), respResult.getMsg());
        }

        return RespResult.ok(new AlrgCreateOutVo(respResult.getData()));
    }

    @PutMapping(value = "/anno/lesion/result/group")
    public RespResult update(@Validated @RequestBody AlrgUpdateInDto input) {
        return lesionResultGroupFeign.update(input);
    }

    @DeleteMapping(value = "/anno/lesion/result/group/{id}")
    public RespResult delete(@PathVariable("id") Integer id) {
        return lesionResultGroupFeign.delete(id);
    }
}
